package com.seesmic
{
	/*
	Copyright 2007 SEESMIC, Inc
	Licensed under the Apache License, Version 2.0 (the "License"); 
	you may not use this file except in compliance with the License. You may obtain a copy of the License at 
	
	http://www.apache.org/licenses/LICENSE-2.0 
	
	Unless required by applicable law or agreed to in writing, 
	software distributed under the License is distributed on an 
	"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
	See the License for the specific language governing permissions and limitations under the License.
	*/
	
	import com.seesmic.events.SeesmicResultEvent;
	import com.seesmic.helper.VersionManager;
	import com.seesmic.methodgroups.Auth;
	import com.seesmic.methodgroups.Friend;
	import com.seesmic.methodgroups.Recording;
	import com.seesmic.methodgroups.Threads;
	import com.seesmic.methodgroups.Timeline;
	import com.seesmic.methodgroups.User;
	import com.seesmic.methodgroups.Videos;
	
	import flash.system.Security;
	
	public class SeesmicService extends ServiceBase
	{
		public var auth:Auth; 
		public var friend:Friend; 
		public var timeline:Timeline;
		public var video:Videos;
		public var user:User
		public var threads:Threads
		public var recording:Recording
		
		public static var END_POINT:String = "http://api.seesmic.com/"
		public static var RECORDING_END_POINT = "rtmp://r.seesmic.com/trc"
		
		internal static var instance:SeesmicService
		public function SeesmicService()
		{
			super();
			
			instance = this;
			
			Security.allowDomain("seesmic.com")
			Security.loadPolicyFile("http://seesmic.com/crossdomain.xml");
				
			auth = new Auth(this)
			friend = new Friend(this)
			timeline = new Timeline(this)
			video = new Videos(this)
			user = new User(this)
			threads = new Threads(this);
			recording = new Recording(this)
			
			auth.addEventListener(SeesmicResultEvent.AUTH_LOGIN, onAuthLogin)
			auth.addEventListener(SeesmicResultEvent.AUTH_LOGOUT, onAuthLogout)
			user.addEventListener(SeesmicResultEvent.USER_ACTIVATE_ACCOUNT, onUserActivation);
			
			VersionManager.getInstance().getVersion()
		}
		
		public var username:String
		public var password:String
		
		
		public var sid:String
		public var session_id:String
		
		public var isLoggedIn:Boolean = false
		private function onAuthLogin(e:SeesmicResultEvent):void
		{
			if(e.success)
			{
			sid = e.data.sid
			session_id= e.data.session_id
			
			isLoggedIn = true
			}
		}
		private function onUserActivation(e:SeesmicResultEvent):void
		{
			if(e.success)
			{
				sid = e.data.login.sid
				session_id = e.data.login.session_id
				
				isLoggedIn = true;
			}
		}
		private function onAuthLogout(e:SeesmicResultEvent):void
		{
			isLoggedIn = false
		}
		
		public function debugMode():void
		{
			Security.allowDomain("qprod.seesmic.com")
			Security.loadPolicyFile("http://qprod.seesmic.com/crossdomain.xml");
			END_POINT = "http://qprod.seesmic.com/"
			RECORDING_END_POINT = "rtmp://qprod.seesmic.com/trc"
			 
		}

	}
}